<?php

class Validate
{
	public function string($str, $criteria = false)
	{
		if(is_string($str))
		{
			if(!$criteria)
			{
				return true;
			}
			
			$hits = 0;
			$t_hits = count($criteria, COUNT_NORMAL);
			
			foreach ($criteria as $c => $val)
			{
				switch ($c)	
				{
					case "length":
						if($val['max'] >= strlen($str) && strlen($str) >= $val['min'])
						{
							$hits++;
						}
						break;
					case "regex_match":
						if(preg_match($val, $str))
						{
							$hits++;
						}
						break;
					case "match":
						if(stripos($str, $val))
						{
							$hits++;
						}
						break;
					default:
						break;
				}
			}
			
			if($hits == $t_hits)
			{
				return true;
			}
		}
		
		return false;
	}
}

?>